# 方法一：mss
from mss import mss
with mss() as screenshot:
    screenshot.shot(output='scr.png')

# 方法二：可截扩展屏
from mss import mss, tools

def screenShot(monitor_num):
    with mss() as sct:
        mon = sct.monitors[monitor_num]

        # The screen part to capture
        monitor = {
            "top": mon["top"],
            "left": mon["left"],
            "width": mon["width"],
            "height": mon["height"],
            "mon": monitor_num,
        }
        output = 'm'+str(monitor_num)+'.png'

        # Grab the data
        sct_img = sct.grab(monitor)
        # Save to the picture file
        tools.to_png(sct_img.rgb, sct_img.size, output=output)

# 方法三：PIL
from win32 import win32gui, win32print
from win32.lib import win32con
from PIL import ImageGrab

def get_real_resolution():
    """获取真实的分辨率"""
    hDC = win32gui.GetDC(0)
    # 横向分辨率
    w = win32print.GetDeviceCaps(hDC, win32con.DESKTOPHORZRES)
    # 纵向分辨率
    h = win32print.GetDeviceCaps(hDC, win32con.DESKTOPVERTRES)
    return w, h

screensize = get_real_resolution()

img = ImageGrab.grab()
# 或 img = ImageGrab.grab(bbox=(0, 0, screensize[0], screensize[1]))
img.save('full_screen_img.jpg')

